<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>教师申请提现信息</title>
    <link rel="stylesheet"th:href="@{/static/lib/bootstrap/bootstrap.min.css}">
    <script th:src="@{/static/lib/jquery/1.9.1/jquery.js}"></script>
    <script th:src="@{/static/lib/jquery.validation/1.14.0/jquery.validate.js}"></script>
    <script th:src="@{/static/lib/jquery.validation/1.14.0/messages_zh.js}"></script>
    <script th:src="@{/static/lib/vue.min.js}"></script>
    <script type="text/javascript" th:src="@{/static/lib/layer/2.4/layer.js}"></script>
</head>
<body>
<form id="editUserForm">
<div class="container">
        <br/>
        <input type="hidden" th:value="${teacher.teacherId}" id="teacherid">
        <div class="form-group" >
            <label for="teacherZhifubao">支付宝账号：</label>
            <input type="text" class="form-control" id="teacherZhifubao" name="zhifubao" th:value="${teacher.teacherZhifubao}">
        </div>
        <div class="form-group">
            <label for="teacherMoney">提现金额：</label>
            <input type="text" class="form-control" id="teacherMoney" name="money" placeholder="请输入提现金额" required="required">
        </div>
        <div class="form-group">
            <label for="teacherTxpwd">提现密码：</label>
            <input type="text" class="form-control" id="teacherTxpwd" name="txpwd"  placeholder="请输入提现密码" required="required" >
        </div>
        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">确定</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
</div>
    </form>


<script type="text/javascript">
    /**
     * LYT 平台管理员处理教师提现
     * @type {*|jQuery|string|undefined}
     */
    var str = $("#teacherZhifubao").val();
    var reg = /^(\d{4})\d+(\d{4})$/;
    str = str.replace(reg, "$1****$2");
    $("#teacherZhifubao").val(str)


   var zhifubao=($("#teacherZhifubao").val())
    if(zhifubao==''){
        layer.alert('您还未绑定支付宝账号，点击确定将跳转到绑定支付宝页面', {
              skin: 'layui-layer-molv' //样式类名  自定义样式
            ,closeBtn: 1    // 是否显示关闭按钮
            ,anim: 1 //动画类型
             ,btn: ['确定','取消'] //按钮
             ,icon: 6    // icon
             ,yes:function(){
                var id=$("#teacherid").val()
                location.href='/addZhifubao/'+id
                }
            ,btn2:function(){
                  window.history.go(-1)
                }});

    }

    var id=$("#teacherid").val()
    var tixianMessage = function(){
        $.ajax({
            type: "POST",
            dataType: "json",
            url: '/toTixianMessage',
            data:{
                teacherZhifubao:$("#teacherZhifubao").val(),
                teacherMoney:$("#teacherMoney").val(),
                teacherTxpwd:$("#teacherTxpwd").val(),
                id:$("#teacherid").val()
            },
            success: function(result){
                if(result==0){
                    layer.msg('提现申请成功，将在两个小时之内到账',{icon:1,time:2000,shade:0.4},function() {
                        window.parent.location.reload(); //刷新父页面
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);  // 关闭layer
            })
                }
                if(result==2){
                    layer.msg('提现金额不合法',{icon:2})
                }
                if(result==3){
                    layer.msg('提现密码不正确',{icon:3})
                }
            }
        });
    }



    function validform(){
        return $("#editUserForm").validate({
            rules:{
                money:{
                    range:[0.01,999999999999]
                },
                txpwd:{
                    minlength:6,
                    maxlength:6
                }
            },
            messages:{
                money:{
                    range:'提现金额不能小于0.01'
                },
                txpwd:{
                    minlength:'提现密码为6位数',
                    maxlength:'提现密码为6位数'
                }
            }
        })
    }
    $(validform());
    $("#saveBtn").click(function () {
        if(validform().form()){
            tixianMessage()
        }else {
        }
    });

    $("#cancelBtn").click(function () {

location.href='/toWallet?id='+[[${session.teacher.teacherId}]]
    })
</script>

</body>
</html>
